package com.itcast.framdemo.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author WangCong
 * 2024/12/7 10:20
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;

    public static <T> JsonResult<T> success(T data) {
        return new JsonResult<>(1, "success", data);
    }

    public static <T> JsonResult<T> success(String msg, T data) {
        return new JsonResult<>(1, msg, data);
    }
    public static <T> JsonResult<T> success(Integer code,String msg, T data) {
        return new JsonResult<>(code, msg, data);
    }
    public static <T> JsonResult<T> error(String msg, T data) {
        return new JsonResult<>(0, msg, data);
    }
    public static <T> JsonResult<T> error(String msg) {
        return new JsonResult<>(0, msg,null);
    }
    public static <T> JsonResult<T> success() {
        return new JsonResult<>(1, "success", null);
    }
}
